const fileService = require('../services/fileService')

// 多人日报导出
const exportMultiDailyWork = async (req, res) => {
  try {
    const stream = await fileService.exportMultiDailyWork(req.query)
    stream.pipe(res)
  } catch (err) {
    res.send(err.message)
  }
}

// 多人excel导出
const exportMultiZsgzExcel = async (req, res) => {
  try {
    const stream = await fileService.exportMultiZsgzExcel(req.query)
    stream.pipe(res)
  } catch (err) {
    res.send(err.message)
  }
}
// 单人日报导出
const exportDailyWork = async (req, res) => {
  try {
    const docxStream = await fileService.exportDailyWork(req.query)
    docxStream.pipe(res)
  } catch (err) {
    res.send(err.message)
  }
}

// 驻商工作导出
const exportZsgzExcel = async (req, res) => {
  try {
    const xlsxStream = await fileService.exportZsgzExcel(req.query)
    xlsxStream.write(res)
  } catch (err) {
    res.json({
      status: 1,
      msg: err.message
    })
  }
}

// 信息摸排导出
const exportInfoWorkItems = async (req, res) => {
  try {
    const docxStream = await fileService.exportInfoWorkItems(req.query)
    docxStream.pipe(res)
  } catch (err) {
    res.json({
      status: 1,
      msg: err.message
    })
  }
}

// 摸排消息导出
const exportMpxxDocx = async (req, res) => {
  try {
    const docxStream = await fileService.exportInfoWorkItems(req.query.date)
    docxStream.pipe(res)
  } catch (err) {
    res.json({
      status: 1,
      msg: err.message
    })
  }
}

module.exports = {
  exportMultiDailyWork,
  exportMultiZsgzExcel,
  exportDailyWork,
  exportZsgzExcel,
  exportInfoWorkItems,
  exportMpxxDocx
}
